package kr.saeildamil.androidstudy_second.ani;

import java.util.ArrayList;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.ViewSwitcher.ViewFactory;

public class ImageSwitcherTest extends Activity {
	/*TextSwitcher mTextSwitcher;*/
	ImageSwitcher mImageSwitcher;
	int mTextIdx;
	int mImageIdx;
	String[] texts;
	ArrayList<Drawable> imgs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_imageswitchertest);

		imgs = new ArrayList<Drawable>();
		imgs.add(getResources().getDrawable(R.drawable.kimtaehi2));
		imgs.add(getResources().getDrawable(R.drawable.leeminjung2));
		imgs.add(getResources().getDrawable(R.drawable.sonyejin3));
		imgs.add(getResources().getDrawable(R.drawable.hangain));

		/*mTextSwitcher = (TextSwitcher) findViewById(R.array.PLANET);*/
		mImageSwitcher = (ImageSwitcher) findViewById(R.id.ch23_imageSwitcher);

		/*mTextSwitcher.setFactory(mTextFactory);
		mTextSwitcher.setText(texts[mTextIdx]);*/

		mImageSwitcher.setFactory(mImageFactory);
		mImageSwitcher.setImageDrawable(imgs.get(mImageIdx));
	}

	ViewSwitcher.ViewFactory mTextFactory = new ViewFactory() {
		public View makeView() {
			TextView text = new TextView(ImageSwitcherTest.this);
			text.setTextSize(22);
			text.setBackgroundColor(Color.YELLOW);
			text.setTextColor(Color.BLACK);
			return text;
		}
	};

	ViewSwitcher.ViewFactory mImageFactory = new ViewFactory() {
		public View makeView() {
			ImageView img = new ImageView(ImageSwitcherTest.this);
			return img;
		}
	};

	public void mOnClick(View v) {
		switch (v.getId()) {
		/*case R.id.ch23_Imageswitcher_textnext:
			mTextIdx = mTextIdx == texts.length - 1 ? 0 : mTextIdx + 1;
			mTextSwitcher.setText(texts[mTextIdx]);
			break;*/
		case R.id.ch23_Imageswitcher_imagenext:
			mImageIdx = mImageIdx == imgs.size() - 1 ? 0 : mImageIdx + 1;
			mImageSwitcher.setImageDrawable(imgs.get(mImageIdx));
			break;
		}
	}
}
